# 板块资金流
# 行业资金流", "概念资金流"
# stock_sector_fund_flow_rank
# https://data.eastmoney.com/bkzj/hy.html
import time

import akshare as ak

from scripts.hy_concent.hy_concent import save_concept


def get_top_hy(indicator="今日", sector_type="行业资金流"):
    stock_sector_fund_flow_rank_hy = ak.stock_sector_fund_flow_rank(indicator, sector_type)
    top20 = stock_sector_fund_flow_rank_hy.head(20).copy()

    net_cols_je = [col for col in top20.columns if '净额' in col]
    net_cols_jzb = [col for col in top20.columns if '净占比' in col]

    # 使用assign创建新列
    formatted_je = {col: (top20[col] / 1e8).round(1).astype(str) + '亿' for col in net_cols_je}
    formatted_jzb = {col: top20[col].astype(str) + '%' for col in net_cols_jzb}

    top20 = top20.assign(**formatted_je, **formatted_jzb)

    last_col = top20.columns[-1]
    top20.insert(2, last_col, top20.pop(last_col))

    return top20


# top20_hy = get_top_hy()
top20_concept = get_top_hy(indicator="今日", sector_type="概念资金流")

# print(top20_hy)
print(top20_concept)

concept_lst = top20_concept["名称"].tolist()
for symbol in concept_lst:
    save_concept(symbol)
    time.sleep(30)


# stock_sector_fund_flow_rank_concent = ak.stock_sector_fund_flow_rank(indicator="今日", sector_type="概念资金流")
